<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" @submit.prevent="">
      <el-row :gutter="8">
        <el-col :lg="6" :md="12" :sm="12" :xs="24">
          <el-form-item label="毕业年份">
            <el-select
              v-model="form.graduationYear"
              multiple
              collapse-tags
              clearable
              style="margin-left: 0;"
              placeholder="请选择毕业年份">
              <el-option
                v-for="item in graduationYearList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :lg="6" :md="12" :sm="12" :xs="24">
          <el-form-item label="毕业年份">
            <el-date-picker
              v-model="form.dateRangeFileTime"
              style="width: 240px"
              value-format="YYYY-MM-DD"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :lg="6" :md="12" :sm="12" :xs="24">
          <el-form-item label-width="16px">
            <el-button type="primary" @click="search">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </ele-card>
</template>

<script setup>
import {ref, watch} from 'vue';
import {useFormData} from '@/utils/use-form-data';
import {selectGraduationYear, selectCurrentYear} from '@/api/manage/statistic/admin/schoolInfo';

const emit = defineEmits(['search']);

/** 表单数据 */
const [form, resetFields] = useFormData({
  graduationYear: [],
  dateRangeFileTime: []
});

/** 搜索 */
const search = () => {
  emit('search', {...form});
};

/**  重置 */
const reset = () => {
  resetFields();
  form.graduationYear.push(currentYear.value);
  search();
};


const graduationYearList = ref([]);

/**
 * 查询后台配置的毕业年份
 */
const getGraduationYear = () => {
  selectGraduationYear().then(res => {
    graduationYearList.value = res;
  });
};


getGraduationYear();


const currentYear = ref('');

const getCurrentYear = () => {
  selectCurrentYear().then(res => {
    currentYear.value = res;
    form.graduationYear.push(currentYear.value);
    search();
  });
}

getCurrentYear();


</script>
